package com.example.demo.tools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description: 全局的配置信息
 * User: su
 * Date: 2023-02-19
 * Time: 11:10
 */
@Configuration
public class ApplicationConfigure implements WebMvcConfigurer {
    // 不拦截的 url
    List<String> excludes = new ArrayList<String>() {
        {
            add("/favicon.ico");
            add("/prepros-6.config");
            add("/img/**");
            add("/fonts/**");
            add("/vendors/**");
            add("/css/**");

            add("/**/*.js");
            add("/**/*.css");
            add("/**/*.map");
            add("/**/*.scss");

            add("");
            add("/");
            add("/index.html");
            add("/about-us.html");
            add("/service.html");
            add("/contact.html");
            add("/adminLogin.html");

            add("/subscribe/add");
            add("/subscribe/delete");

            add("/contact/add");

            add("/member/getAll");

            add("/administrator/login");
        }
    };

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            InterceptorRegistration registration = registry.addInterceptor(loginInterceptor);
            // 拦截的路径
            registration.addPathPatterns("/**");
            // 放行的路径no
            registration.excludePathPatterns(excludes);

//        registry.addInterceptor(loginInterceptor)
//                .addPathPatterns("");
    }
}
